import redis
import logging


# 配置flask
class Config(object):
    # 配置日志等级
    LOG_LEVEL = logging.DEBUG
    # 配置数据库
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/manager11"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True # 视图函数结束后自动提交

    # 配置redis数据库
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    # 配置CSRF---包含请求体的请求都需要开启CSRF，防止恶意请求
    # 秘钥
    SECRET_KEY = "fhajsdhfksdhfkjas"

    # 配置flask_session,将session会话的数据存储在redis中
    SESSION_TYPE = 'redis'  # 指定session保存到redis
    SESSION_USE_SIGNER = True  # 让cookie中的session_id 被加密签名处理
    SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    PERMANENT_SESSION_LIFETIME = 86400  # session的有效期，单位秒


class DevelopmentConfig(Config):
    DEBUG = True


class ProductionConfig(Config):
    DEBUG = False
    LOG_LEVEL = logging.ERROR


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig
}
